<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>缤格</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/swiper.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/binge.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/swiper.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>

    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<!-- header -->
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <div class="header" style="margin-bottom: 0;">
        <div class="head-back">
            <a href="javascript:void(0);" tapmode onclick="comeBack()" class="back-btn"></a>
        </div>
        <div class="head-title">
            <h6>关注的学校</h6>
        </div>
        <!--<div class="head-action">-->
        <!--<a href="javascript:void(0);" tapmode onclick="commonUrl('')" class="action-btn"></a>-->
        <!--</div>-->
    </div>
</div>

<!-- header end -->
<div class="mescroll" id="mescroll" style="padding-top: 1.5rem;">
    <div class="follow-school">
        <div class="follow-school-list" style="border-bottom: 0.2rem #ededed solid;">
            <div class="common-title">
                <h6>我的母校</h6>
            </div>
            <ul id="selfSchool">
                <!--<li>
                    <div class="flex-school">
                        <div class="school-info">
                            <div class="school-img">
                                <img src="../../image/school-icon.png" alt="">
                            </div>
                            <div class="info">
                                <h6>浙江大学 <span class="mother-school">母校</span></h6>
                                <p class="single-ellipsis">最早创办的现代高等学府之一</p>
                            </div>
                        </div>
                    </div>
                    <div class="school-action">
                        <dl>
                            <dd>
                                <p class="icon1">开启比赛提醒</p>
                                <div class="switch on"><span class="slider"></span></div>
                            </dd>
                        </dl>
                    </div>
                </li>-->
            </ul>
        </div>
        <div class="follow-school-list">
            <div class="common-title">
                <h6>我的关注</h6>
                <a href="javascript:void(0);" class="more" tapmode onclick="commonUrl('choose_school')">更多></a>
            </div>
            <ul id="otherSchool">
                <!--<li>
                    <div class="flex-school">
                        <div class="school-info">
                            <div class="school-img">
                                <img src="../../image/school-icon.png" alt="">
                            </div>
                            <div class="info">
                                <h6>浙江大学</h6>
                                <p class="single-ellipsis">最早创办的现代高等学府之一</p>
                            </div>
                        </div>
                    </div>
                    <div class="school-action">
                        <dl>
                            <dd>
                                <p class="icon1">开启比赛提醒</p>
                                <div class="switch on"><span class="slider"></span></div>
                            </dd>
                            <dd>
                                <a href="javascript:void(0);" tapmode onclick="commonUrl()" class="follow">取消关注</a>
                            </dd>
                        </dl>
                    </div>
                </li>-->
            </ul>
        </div>
    </div>
</div>



</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<link rel="stylesheet" type="text/css" href="../../css/mescroll.min.css"/>
<script type="text/javascript" src="../../script/mescroll.min.js"></script>
<script type="text/javascript">
    apiready = function () {

        setFixStatusBar(); //设置状态栏
        pop.loading();
        keybackListener()
        //选择关注学校返回的监听
        api.addEventListener({
            name: 'chooseFollowSchool'
        }, function (ret, err) {
            getMyFollowSchool();
        });

        // dropDownRefresh(function () {
        //
        // })

        getMyFollowSchool();
    }

    //创建MeScroll对象
    var mescroll = new MeScroll("mescroll", {
        down: {
            auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
            callback: downCallback //下拉刷新的回调
        }
    });
    /*下拉刷新的回调 */
    function downCallback() {
        getMyFollowSchool();

        //mescroll.endErr();
    }


    //获取关注的学校
    function getMyFollowSchool() {
        var param = {
            token: $api.getStorage('token'),
        }
        getAjax(Interface.school_follow, param, function (res) {

            var list = res.data;
            if (isDefine(list)) {

                var selfSchool = '';

                var self_school = list.self;
                if(isDefine(self_school)){
                    var html = '';
                    if(self_school.match_status == 2){
                        html = '<div class="switch" data-id="'+self_school.id+'"><span class="slider"></span></div>'
                    }else {
                        html = '<div class="switch on" data-id="'+self_school.id+'"><span class="slider"></span></div>'
                    }

                    selfSchool = '<li>' +
                        '                <div class="flex-school">' +
                        '                    <div class="school-info">' +
                        '                        <div class="school-img">' +
                        '                            <img src="'+ajaxUrl+self_school.icon_path+'" alt="">' +
                        '                        </div>' +
                        '                        <div class="info">' +
                        '                            <h6>'+self_school.title+' <span class="mother-school">母校</span></h6>' +
                        '                            <p class="single-ellipsis">'+self_school.school_motto+'</p>' +
                        '                        </div>' +
                        '                    </div>' +
                        '                </div>' +
                        '                <div class="school-action">' +
                        '                    <dl>' +
                        '                        <dd>' +
                        '                            <p class="icon1">开启比赛提醒</p>' + html +
                        '                        </dd>' +
                        '                    </dl>' +
                        '                </div>' +
                        '            </li>'
                    $('#selfSchool').html(selfSchool);
                }



                var otherSchool = '';
                var other_school = list.list;
                if(isDefine(other_school)){

                    for(var i = 0;i<other_school.length;i++){

                        var html = '';
                        if(other_school[i].match_status == 2){
                            html = '<div class="switch" data-id="'+other_school[i].id+'"><span class="slider"></span></div>'
                        }else {
                            html = '<div class="switch on" data-id="'+other_school[i].id+'"><span class="slider"></span></div>'
                        }

                        otherSchool += '<li>' +
                            '                <div class="flex-school">' +
                            '                    <div class="school-info">' +
                            '                        <div class="school-img">' +
                            '                            <img src="'+ajaxUrl+other_school[i].icon_path+'" alt="">' +
                            '                        </div>' +
                            '                        <div class="info">' +
                            '                            <h6>'+other_school[i].title+'</h6>' +
                            '                            <p class="single-ellipsis">'+other_school[i].school_motto+'</p>' +
                            '                        </div>' +
                            '                    </div>' +
                            '                </div>' +
                            '                <div class="school-action">' +
                            '                    <dl>' +
                            '                        <dd>' +
                            '                            <p class="icon1">开启比赛提醒</p>' + html +
                            '                        </dd>' +
                            '                        <dd>' +
                            '                            <a href="javascript:void(0);" tapmode onclick="cancelFollow('+other_school[i].id+')" class="follow">取消关注</a>' +
                            '                        </dd>' +
                            '                    </dl>' +
                            '                </div>' +
                            '            </li>'



                    }
                    $("#otherSchool").html(otherSchool)
                }else {
                    $("#otherSchool").html(noData)
                }

            }else {
                $('#shelf_school').html('<p style="width: 100%;" class="t-c c-999">暂无母校数据</p>');
                $("#otherSchool").html(noData)
            }
            pop.close()
            mescroll.endErr()
        }, function (error) {

            $('#shelf_school').html('<p style="width: 100%;" class="t-c c-999">暂无母校数据</p>');
            $("#otherSchool").html(noData)

            pop.notice(error.msg);
            pop.close()
            mescroll.endErr()
        })

    }

    function cancelFollow(school_id){
        var stype = 2;//取消关注
        var type = 2;//1为会员，2为圈子
        follow(stype,type,school_id,function (res) {
            pop.notice('已取消关注');
            api.sendEvent({
                name: 'followSchool',
                extra: {}
            });
            setTimeout(function () {
                getMyFollowSchool();
            },1000)
        })
    }



    //比赛开启提醒
    $(".follow-school-list").on('click', '.switch', function () {

        var _this = $(this);
        var _thisType = _this.attr('data-id');
        if (_this.hasClass('on')) {
            _this.removeClass('on');
            set_match_school(_thisType,2)
        } else {
            _this.addClass('on');
            set_match_school(_thisType,1)
        }
    })


    function set_match_school(circle_id,switchType){
        var param = {
            token: $api.getStorage('token'),
            circle_id: circle_id,
            type: switchType,//类型：1开启提醒 2关闭提醒
        }
        getAjax(Interface.set_match_school, param, function (res) {

            if(switchType == 1){
                pop.notice('已开启提醒')
            }else {
                pop.notice('已取消提醒')
            }

        },function (error) {
            pop.notice(error.msg)
            pop.close()
        })


    }

    //下拉
    $(".follow-school-list").on('click', '.flex-school', function () {
        var _this = $(this);
        if (_this.hasClass('on')) {
            _this.removeClass('on');
        } else {
            _this.addClass('on');
        }
        _this.siblings('.school-action').slideToggle();

    })


</script>
